home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / APNDLIST.ASM < prev    next >
Assembly Source File  |  1992-03-09  |  4KB  |  144 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.         extrn    sl_malloc:far
  6.  
  7.  
  8. wp        equ    <word ptr>        ;I'm a lazy typist
  9.  
  10.  
  11. ; Special case to handle MASM 6.0 vs. all other assemblers:
  12. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  13.  
  14.         ifndef    @version
  15. @version    equ    500
  16.         endif
  17.  
  18.  
  19.  
  20. StdGrp        group    stdlib,stddata
  21. stddata        segment    para public 'sldata'
  22. stddata        ends
  23.  
  24. stdlib        segment    para public 'slcode'
  25.         assume    cs:stdgrp
  26.  
  27. ; sl_AppendLast-    DX:SI points at a list node.
  28. ;            ES:DI points at a list.
  29. ;            Append the node to the end of the list
  30. ;
  31. ; Randall Hyde  3/3/92
  32. ;
  33.  
  34.         public    sl_AppendLast
  35. sl_AppendLast    proc    far
  36.         push    ds
  37.         push    es
  38.         push    di
  39.  
  40.         if    @version ge 600
  41.  
  42. ; MASM 6.0 version goes here
  43.  
  44.         mov    wp es:[di].List.CurrentNode, si    ;Set ptr to current
  45.         mov    wp es:[di].List.CurrentNode+2, dx
  46.  
  47.         mov    ds, dx
  48.         cmp    wp es:[di].List.Tail+2, 0    ;Empty list?
  49.         jne    HasAList
  50.  
  51. ; At this point, the Tail pointer is zero.  This only occurs if the
  52. ; list is empty.  So point the Head and Tail pointers to the new node.
  53. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  54. ; package assumes that if the segment is zero, the whole thing is zero.
  55. ; So don't put any nodes into segment zero!
  56.  
  57.         mov    wp es:[di].List.Head, si
  58.         mov    wp es:[di].List.Head+2, dx
  59.         mov    wp es:[di].List.Tail, si
  60.         mov    wp es:[di].List.Tail+2, dx
  61.         mov    wp ds:[si].Node.Next, 0            ;Set all the links
  62.         mov    wp ds:[si].Node.Next+2, 0    ; in the first node
  63.         mov    wp ds:[si].Node.Prev, 0        ; to NIL.
  64.         mov    wp ds:[si].Node.Prev+2, 0
  65.         pop     di
  66.         pop    es
  67.         pop    ds
  68.         jmp    AppendDone
  69.  
  70. ; If the Tail pointer is non-NIL, append the new node to the end of the
  71. ; list down here.
  72.  
  73. HasAList:    les    di, es:[di].List.Tail        ;Get ptr to end
  74.         mov    wp es:[di].Node.Next, si    ;Append current node
  75.         mov    wp es:[di].Node.Next+2, dx    ; to end of list.
  76.         mov    wp ds:[si].Node.Prev, di    ;Link in back ptr.
  77.         mov    wp ds:[si].Node.Prev+2, es
  78.         mov    wp ds:[si].Node.Next, 0        ;Set next field of
  79.         mov    wp ds:[si].Node.Next+2, 0    ; to NIL.
  80.         pop    di                ;Return ptr to list
  81.         pop    es                ; variable.
  82.         mov    wp es:[di].List.Tail, si    ;Update last ptr.
  83.         mov    wp es:[di].List.Tail+2, dx
  84.         pop    ds
  85.  
  86.  
  87.  
  88.  
  89.         else
  90.  
  91. ; All other assemblers come down here:
  92.  
  93.         mov    wp es:[di].CurrentNode, si    ;Set ptr to current
  94.         mov    wp es:[di].CurrentNode+2, dx    ; node here.
  95.  
  96.         mov    ds, dx
  97.         cmp    wp es:[di].Tail+2, 0    ;Empty list?
  98.         jne    HasAList
  99.  
  100. ; At this point, the Tail pointer is zero.  This only occurs if the
  101. ; list is empty.  So point the Head and Tail pointers to the new node.
  102. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  103. ; package assumes that if the segment is zero, the whole thing is zero.
  104. ; So don't put any nodes into segment zero!
  105.  
  106.         mov    wp es:[di].Head, si
  107.         mov    wp es:[di].Head+2, dx
  108.         mov    wp es:[di].Tail, si
  109.         mov    wp es:[di].Tail+2, dx
  110.         mov    wp ds:[si].Next, 0            ;Set all the links
  111.         mov    wp ds:[si].Next+2, 0        ; in the first node
  112.         mov    wp ds:[si].Prev, 0        ; to NIL.
  113.         mov    wp ds:[si].Prev+2, 0
  114.         pop     di
  115.         pop    es
  116.         pop    ds
  117.         jmp    AppendDone
  118.  
  119. ; If the Tail pointer is non-NIL, append the new node to the end of the
  120. ; list down here.
  121.  
  122. HasAList:    les    di, es:[di].Tail        ;Get ptr to end
  123.         mov    wp es:[di].Next, si        ;Append current node
  124.         mov    wp es:[di].Next+2, dx        ; to end of list.
  125.         mov    wp ds:[si].Prev, di        ;Link in back ptr.
  126.         mov    wp ds:[si].Prev+2, es
  127.         mov    wp ds:[si].Next, 0        ;Set next field of
  128.         mov    wp ds:[si].Next+2, 0        ; to NIL.
  129.         pop    di                ;Return ptr to list
  130.         pop    es                ; variable.
  131.         mov    wp es:[di].Tail, si        ;Update last ptr.
  132.         mov    wp es:[di].Tail+2, dx
  133.         pop    ds
  134.  
  135.         endif
  136.  
  137. AppendDone:
  138.         ret
  139.  
  140. sl_AppendLast    endp
  141.  
  142. stdlib        ends
  143.         end
  144.